home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / pcl4p341.zip / MODEM_IO.PAS < prev    next >
Pascal/Delphi Source File  |  1992-12-24  |  3KB  |  133 lines

  1. (*********************************************)
  2. (*                                           *)
  3. (*  Talks to your modem. Called by TERM.PAS  *)
  4. (*                                           *)
  5. (*  This program is donated to the Public    *)
  6. (*  Domain by MarshallSoft Computing, Inc.   *)
  7. (*  It is provided as an example of the use  *)
  8. (*  of the Personal Communications Library.  *)
  9. (*                                           *)
  10. (*********************************************)
  11.  
  12. unit Modem_IO;
  13.  
  14. interface
  15.  
  16. type
  17.   String80 = String[80];
  18.  
  19.  
  20. procedure SendTo( Port:Integer; ThisString:String80);
  21. function  WaitFor( Port:Integer; ThisString:String80):Boolean;
  22.  
  23. implementation
  24.  
  25. uses PCL4P;
  26.  
  27. function BreakTest : Boolean;
  28. begin
  29.   if SioBrkKey then
  30.     begin
  31.       WriteLn('User BREAK');
  32.       BreakTest := TRUE
  33.     end
  34.   else BreakTest := FALSE;
  35. end;
  36.  
  37.  
  38. procedure SendTo( Port: Integer; ThisString:String80);
  39. const
  40.    CR = 13;
  41. var
  42.    rc : Integer;
  43.    i  : Integer;
  44.    c  : Char;
  45. begin
  46.    rc := SioRxFlush(Port);
  47.    rc := SioDelay(4);
  48.    for i := 1 to Length(ThisString) do
  49.       begin
  50.          c := UpCase(ThisString[i]);
  51.          case c of
  52.             '!' : c := chr(CR);
  53.             '~' : begin
  54.                      (* delay 1/2 second *)
  55.                      rc := SioDelay(9);
  56.                      c := ' '
  57.                   end;
  58.              ' ': rc := SioDelay(3);
  59.          end;
  60.          (* transmit as 7 bit char *)
  61.          rc := SioPutc(Port, chr(ord(c) and $7f));
  62.          (* wait 3/18th of a second *)
  63.          rc := SioDelay(3);
  64.          (* wait 1 second for echo *)
  65.          rc := SioGetc(Port,18);
  66.          if rc > 0 then Write(chr(rc));
  67.       end (* for *)
  68. end; (* SendTo *)
  69.  
  70. Function WaitFor(Port:Integer; ThisString:String80): Boolean;
  71. label WaitForExit;
  72. const
  73.   CR = 13;
  74.   LF = 10;
  75.  
  76. var
  77.   code : Integer;
  78.   c : Char;
  79.   i : Integer;
  80.   rc: Integer;
  81.  
  82. procedure Flush;
  83. label FlushExit;
  84. var code : integer;
  85. begin
  86.   while TRUE do
  87.     begin
  88.        if BreakTest then exit;
  89.        (* get next incoming character *)
  90.        code := SioGetc(Port,38);
  91.        if code = -1 then exit;
  92.        (* skip CR & LF *)
  93.        if (code <> CR) and (code <> LF) then
  94.          begin
  95.            (*writeln('Pushing ',chr(code),' [',code,']');*)
  96.            rc := SioUnGetc(Port, code );
  97.            goto FlushExit;
  98.          end;
  99.     end; (* while *)
  100. FlushExit: end; (* Flush *)
  101.  
  102. begin (* WaitFor *)
  103.   Write( chr(LF) );
  104.   Flush;
  105.   for i:= 1 to Length(ThisString) do
  106.     begin
  107.        (* control-BREAK ? *)
  108.        if BreakTest then exit;
  109.        (* c is expected character *)
  110.        c := UpCase( ThisString[i] );
  111.        (* wait 1 second for next character *)
  112.        code := SioGetc(Port,18);
  113.        if code = -1 then
  114.           begin
  115.              WaitFor := FALSE;
  116.              goto WaitForExit;
  117.           end;
  118.        (* echo character from modem *)
  119.        Write(chr(code));
  120.        if chr(code) <> c then
  121.           begin
  122.              writeln('Expecting ',c,' not ',chr(code),'[',code,']');
  123.              WaitFor := FALSE;
  124.              goto WaitForExit;
  125.           end;
  126.     end; (* for *)
  127.   (* a last character ? *)
  128.   rc := SioGetc(Port,18);
  129.   if rc > 0 then Write(chr(rc));
  130.   WaitFor := TRUE;
  131. WaitForExit: end; (* WaitFor *)
  132.  
  133. end.